//
//  StatusTopCell.swift
//  01-WeiBo
//
//  Created by 李晓东 on 17/7/7.
//  Copyright © 2017年 PeanutXu. All rights reserved.
//

import UIKit
import SDWebImage

class StatusTopCell: UIView {

    var viewModel : StatusModel? {
        didSet{
            iconView.sd_setImage(with: URL(string: (viewModel!.status.user?.profile_image_url)!))
            nameLabel.text = viewModel?.status.user?.screen_name
            memberIconView.image = UIImage(named: "common_icon_membership_level\(viewModel!.status.user!.mbrank)")
            
            let image = setVipImage(verified_type: (viewModel?.status.user?.verified_type)!)! as UIImage
            vipIconView.image = image
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.red
        setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setUI() {
        self.addSubview(iconView)
        self.addSubview(nameLabel)
        self.addSubview(memberIconView)
        self.addSubview(vipIconView)
        
        iconView.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left).offset(16)
            make.top.equalTo(self.snp.top).offset(16)
            make.width.equalTo(StatusCellIconWidth)
            make.height.equalTo(StatusCellIconWidth)
        }
        
        nameLabel.snp.makeConstraints { (make) in
            make.left.equalTo(iconView.snp.right).offset(StatusCellMargin)
            make.top.equalTo(iconView.snp.top)
            
        }
        
        memberIconView.snp.makeConstraints { (make) in
            make.left.equalTo(nameLabel.snp.right).offset(StatusCellMargin)
            make.top.equalTo(nameLabel.snp.top)
            
        }
        
        vipIconView.snp.makeConstraints { (make) in
            make.right.equalTo(iconView.snp.right).offset(5)
            make.bottom.equalTo(iconView.snp.bottom).offset(5)
        }
    }

    lazy var iconView : UIImageView = UIImageView(imageName: "avatar_default_big")
    lazy var nameLabel : UILabel = UILabel(labelTxt: "李有钱")
//    static var memberIconView : UIImageView?
    
    private lazy var memberIconView: UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    /// 认证图标
    private lazy var vipIconView: UIImageView = UIImageView(imageName: "avatar_vip")
    /// 时间标签
    private lazy var timeLabel: UILabel = UILabel(labelTxt: "现在", font: UIFont.systemFont(ofSize: 11), textColor: UIColor.orange)//(title: "现在", fontSize: 11, color: UIColor.orangeColor())
    /// 来源标签
    private lazy var sourceLabel: UILabel = UILabel(labelTxt: "来源")
    
    
    
}


extension StatusTopCell{
    func setVipImage(verified_type:Int) -> UIImage? {
        switch(verified_type ) {
            case 0: return UIImage(named: "avatar_vip")!
            case 2, 3, 5: return UIImage(named: "avatar_enterprise_vip")!
            case 220: return UIImage(named: "avatar_grassroot")!
            default: return nil
        }
    }

}
